package com.example.demo.demos.web.test;


import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RequestMapping("/user")
@RestController
public class User {
    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session){
        if(StringUtils.hasLength(userName)&&StringUtils.hasLength(password)){
            if("zyh".equals(userName)&&"123".equals(password)){
                session.setAttribute("username",userName);
                return true;
            }
        }
        return false;
    }

    @RequestMapping("/getName")
    public String getName(HttpSession session){
        return (String) session.getAttribute("username");
    }
}
